using System;
using System.Collections.Generic;
using System.Linq;
using WinForms = System.Windows.Forms;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using SmokinAces.Object_Classes;
using SmokinAces.Object_Classes.Objects;

namespace SmokinAces
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game_Engine : Main_Engine
    {
        GraphicsDeviceManager graphics;
        public SpriteBatch spriteBatch;
        public VertexDeclaration VertexColor;
        public VertexDeclaration VertexPosColor;
        bool bounds = false;
        Matrix viewMatrix;
        Matrix projectionMatrix;
        //public List<NPC> Npcs;
        GUI GUInterface;
        SpriteFont mMenuFont;
        Menu mMainMenu;
        Menu mPauseMenu;
        Texture2D mMainMenuTexture;
        Texture2D mPauseMenuTexture;
        Texture2D mMapTexture;
        KeyboardState lastKeyState;
        KeyboardState keyState;
        bool mIsMainMenu;
        bool mIsPaused;
        bool mIsShowingMap;
        int screenWidth;
        int screenHeight;

 
        public Game_Engine()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";            
            int LayerCount = Enum.GetNames(typeof(Layers)).Length;
            Draw_Functions = new List<Sort_Delegate>[LayerCount];
            for (int i = 0; i < LayerCount; i++)
            {
                Draw_Functions[i] = new List<Sort_Delegate>();
            }
            //Npcs = new List<NPC>();
            
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            //----------------Initialize our Layers--------------
            //----------------Adding a new Layer to the layers enum propogates here.
            int LayerCount = Enum.GetNames(typeof(Layers)).Length;
            Drawing_List = new Dictionary<string,Texture_List>[LayerCount];
            for (int i = 0; i < LayerCount; i++)
            {
                Drawing_List[i] = new Dictionary<string, Texture_List>();
            }
            //---------------------------------------------------
            graphics.PreferredBackBufferWidth = 1024;
            graphics.PreferredBackBufferHeight = 768;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();

            Window.Title = "Smoking Aces: The Adventure Game";

            mIsMainMenu = true;
            mIsPaused = false;
            graphics.DeviceReset += new EventHandler(graphics_DeviceReset);

            WinForms.Form FormHandle = (WinForms.Form)WinForms.Form.FromHandle(Window.Handle);
            FormHandle.FormClosing += new System.Windows.Forms.FormClosingEventHandler(FormHandle_FormClosing);
            base.Initialize();
        }

        void FormHandle_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            SoundManager.FadeMusic();
            this.Exit();
        }

        void graphics_DeviceReset(object sender, EventArgs e)
        {
            GraphicsDevice.RenderState.AlphaBlendEnable = true;
            GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
            GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Initialize the audio stuff
            SoundManager.Initialize(this);

            // Menu Items stuff
            screenWidth = graphics.PreferredBackBufferWidth;
            screenHeight = graphics.PreferredBackBufferHeight;
            GUIFont12 = Content.Load<SpriteFont>("Fonts/Sans12");
            GUIFont16 = Content.Load<SpriteFont>("Fonts/Sans16");
            mMenuFont = Content.Load<SpriteFont>("Fonts/menufont");

            Color unselectedMainMenu = Color.CornflowerBlue;
            Color selectedMainMenu = Color.DarkRed;

            Color unselectedPauseMenu = Color.DarkSlateGray;
            Color selectedPauseMenu = Color.DarkRed;

            mMainMenu = new Menu(unselectedMainMenu, selectedMainMenu, mMenuFont);
            mMainMenu.AddMenuItem("New Game", new Vector2((screenWidth / 2) - 90, 325));
            mMainMenu.AddMenuItem("Load Game", new Vector2((screenWidth / 2) - 90, 375));
            mMainMenu.AddMenuItem("Options", new Vector2((screenWidth / 2) - 90, 425));
            mMainMenu.AddMenuItem("Quit", new Vector2((screenWidth / 2) - 90, 475));

            mPauseMenu = new Menu(unselectedPauseMenu, selectedPauseMenu, mMenuFont);
            mPauseMenu.AddMenuItem("Return to Game", new Vector2((screenWidth / 2) - 90, 325));
            mPauseMenu.AddMenuItem("Load Game", new Vector2((screenWidth / 2) - 90, 375));
            mPauseMenu.AddMenuItem("Save", new Vector2((screenWidth / 2) - 90, 425));
            mPauseMenu.AddMenuItem("Save And Quit", new Vector2((screenWidth / 2) - 90, 475));
            mPauseMenu.AddMenuItem("Quit", new Vector2((screenWidth / 2) - 90, 525));
                       
            mMainMenuTexture = Content.Load<Texture2D>("Backgrounds/mainmenu");
            mPauseMenuTexture = Content.Load<Texture2D>("Backgrounds/pausemenu");
            mMapTexture = Content.Load<Texture2D>("Backgrounds/map");

            // TODO: use this.Content to load your game content here
            viewMatrix = Matrix.CreateLookAt(new Vector3(GraphicsDevice.Viewport.Width / 2.0f, GraphicsDevice.Viewport.Height / 2.0f, 927), new Vector3(GraphicsDevice.Viewport.Width / 2.0f, GraphicsDevice.Viewport.Height / 2.0f, 0.0f), Vector3.Up);
            //projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1.0f, 1024.0f);
            projectionMatrix = Matrix.CreateOrthographicOffCenter(CurrentScreen.Min.X, CurrentScreen.Max.X, CurrentScreen.Min.Y, CurrentScreen.Max.Y, 0.0f, 1024.0f);

                //.CreateOrthographic(1024.0f, 768.0f, 0.0f, 1024.0f);
            VertexColor = new VertexDeclaration(GraphicsDevice, VertexPositionColorTexture.VertexElements);
            VertexPosColor = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements);
            //----------Build the Quadtree
            BoundingBox MapSize = new BoundingBox(new Vector3(0, 0, -1000.0f), new Vector3(6400, 6400, 1000.0f));
            MapObjects = new Quadtree(MapSize);
            /*
            foreach (Game_Object npc in Npcs)
            {
                MapObjects.Add(npc);
            }
            */
            //--------Audio to Load
            SoundManager.LoadSong("earth_song");
            SoundManager.LoadSong("gameover");
            SoundManager.LoadSong("ThemeMusic");
            SoundManager.LoadSound("Step1");
            SoundManager.LoadSound("Step2");
            SoundManager.LoadSound("Step3");
            SoundManager.LoadSound("Sword");
            SoundManager.LoadSound("PotBreak");
            SoundManager.LoadSound("FireBall");
            SoundManager.LoadSound("FireBallHit");
            SoundManager.LoadSound("IceBolt");
            SoundManager.LoadSound("IceBoltHit");
            SoundManager.LoadSound("Death");
            //------------------------------
            HashSet<Game_Object> TempList = MapObjects.Intersections(CurrentScreen);
            foreach (Game_Object iter in TempList)
            {
                //---Only Start Drawing if the remove succeeded and it's a drawing object
                if (iter is Draw_Object)
                {
                    (iter as Draw_Object).startDraw();
                }
                if (iter is Logic_Object)
                {
                    (iter as Logic_Object).startUpdate();
                }
            }

            
            /*
            Hero.startDraw();
            Hero.startUpdate();
             * */
            GameObjects = TempList.ToList<Game_Object>();
            //----------------------------
            effect = new Game_Effect(this); //new BasicEffect(this.GraphicsDevice,null);
            effect.EnableTinting();
			effect.HeatWave.Amplitude = 1.5f;  //This looks like the grass is blowing with these values!  Good Work Derick!
			effect.HeatWave.Phase = 256f;
			//---- for debugging only...
			//effect.SetHeatWave();
			 //effect.SetMoonLight();
			//effect.SetBrightLight();

            LineEffect = new BasicEffect(this.GraphicsDevice, null);
            //LineEffect.CurrentTechnique = LineEffect.Techniques["colored"];
            LineEffect.VertexColorEnabled = true;
            LineEffect.TextureEnabled = false;


            GraphicsDevice.RenderState.AlphaBlendEnable = true;
            GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
            GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
			UpdateObjects.Add(effect.Update);
            GUInterface = new GUI(this);
        }
        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }
        protected void ProcessGameOverKeyboard()
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (keyState.IsKeyDown(Keys.Escape))
            {
                SoundManager.FadeMusic();
                Exit();
            }
        }
        /// <summary>
        /// Process Input when in Game Mode
        /// </summary>
        protected void ProcessGameKeyboard()
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (keyState.IsKeyDown(Keys.Escape))
            {
                SoundManager.FadeMusic();
                Exit();
            }
            if (keyState.IsKeyDown(Keys.LeftShift))
            {
                bool none = false;
                if (keyState.IsKeyDown(Keys.Multiply) && !lastKeyState.IsKeyDown(Keys.Multiply))
                {
                    bounds = !bounds;
                }
                if (keyState.IsKeyDown(Keys.W))
                {
                    Hero.interact(Actions.north);
                    none = true;
                }
                if (keyState.IsKeyDown(Keys.D))
                {
                    Hero.interact(Actions.east);
                    none = true;
                }
                if (keyState.IsKeyDown(Keys.A))
                {
                    Hero.interact(Actions.west);
                    none = true;
                }
                if (keyState.IsKeyDown(Keys.S))
                {
                    Hero.interact(Actions.south);
                    none = true;
                }
                if (!none)
                {
                    Hero.interact(Actions.none);
                }
            }
            else
            {
                bool none = false;
                if (keyState.IsKeyDown(Keys.W))
                {
                    Hero.interact(Actions.run_north);
                    none = true;
                }
                if (keyState.IsKeyDown(Keys.D))
                {
                    Hero.interact(Actions.run_east);
                    none = true;
                }
                if (keyState.IsKeyDown(Keys.A))
                {
                    Hero.interact(Actions.run_west);
                    none = true;
                }
                if (keyState.IsKeyDown(Keys.S))
                {
                    Hero.interact(Actions.run_south);
                    none = true;
                }
                if (!none)
                {
                    Hero.interact(Actions.none);
                }
            }

            if (keyState.IsKeyDown(Keys.F) && Hero.currentMana >= 10)
            {
                //if (Hero.castFireball(this)); boolean logic to play fireball sound or not

                Hero.castFireball(this);
            }
            if (keyState.IsKeyDown(Keys.I) && Hero.currentMana >= 0)
            {
                Hero.castIceBolt(this);
            }
            if (keyState.IsKeyDown(Keys.Space) && !lastKeyState.IsKeyDown(Keys.Space))
            {
                Hero.interact(Actions.swing_sword);
            }
            if (keyState.IsKeyDown(Keys.Q) && !lastKeyState.IsKeyDown(Keys.Q))
            {
                Hero.interact(Actions.draw_sword);
            }
            if (keyState.IsKeyDown(Keys.P))
            {
                SoundManager.PauseMusic();
                mIsPaused = true;
            }
            if (keyState.IsKeyDown(Keys.M))
            {
                mIsShowingMap = true;
            }
			if (keyState.IsKeyDown(Keys.F1))
			{
				effect.SetNormalLight();
				effect.SetGeneric();
			}
			if (keyState.IsKeyDown(Keys.F2))
			{
				effect.HeatWave.Amplitude = 0.25f;
				effect.HeatWave.Phase = 512f;
				effect.SetHeatWave();
			}
			if (keyState.IsKeyDown(Keys.F3))
			{
				effect.HeatWave.Amplitude = 1.5f;
				effect.HeatWave.Phase = 192f;
				effect.SetHeatWave();
			}
			if (keyState.IsKeyDown(Keys.F4))
			{
				effect.SetMoonLight();
			}
			if (keyState.IsKeyDown(Keys.F5))
			{
				effect.SetBrightLight();
			}
			if (keyState.IsKeyDown(Keys.F6))
			{
				effect.SetNormalLight();
			}
			if (keyState.IsKeyDown(Keys.F7))
			{
				effect.SetThunderStorm(0.05f, 160f);
			}
        }
        /// <summary>
        /// Process Input when in the Game Main Menu
        /// </summary>
        protected void ProcessMenuKeyboard()
        {

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (keyState.IsKeyDown(Keys.Escape))
            {
                SoundManager.FadeMusic();
                Exit();
            }
            if (keyState.IsKeyDown(Keys.Down) && !lastKeyState.Equals(keyState)) mMainMenu.SelectNext();

            if (keyState.IsKeyDown(Keys.Up) && !lastKeyState.Equals(keyState)) mMainMenu.SelectPrev();

            if (keyState.IsKeyDown(Keys.Enter) || keyState.IsKeyDown(Keys.Space))
            {
                string selection = mMainMenu.GetSelectedName();

                if (selection == "New Game")
                {
                    Map.Create_Map(GraphicsDevice, this);
                    mIsMainMenu = false;
                    SoundManager.PlayMusic("ThemeMusic");
                }
                else if (selection == "Load Game")
                {
                    if (this.loadFile())
                    {
                        mIsMainMenu = false;
                        //-------Could probably link what music 
                        //---is being played to the map.
                        SoundManager.PlayMusic("ThemeMusic");
                    }
                    // ADD LOAD FUNCTIONALITY HERE
                }
                else if (selection == "Options")
                {
                    // ADD OPTION FUCTIONALITY HERE
                }
                else if (selection == "Quit")
                {
                    SoundManager.FadeMusic();
                    Exit();
                }
            }

        }

        /// <summary>
        /// Process Input when in the Game Pause Menu
        /// </summary>
        protected void ProcessPauseKeyboard()
        {

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (keyState.IsKeyDown(Keys.Escape))
            {
                SoundManager.FadeMusic();
                Exit();
            }
            if (keyState.IsKeyDown(Keys.Down) && !lastKeyState.Equals(keyState)) mPauseMenu.SelectNext();

            if (keyState.IsKeyDown(Keys.Up) && !lastKeyState.Equals(keyState)) mPauseMenu.SelectPrev();

            if (keyState.IsKeyDown(Keys.Enter) || keyState.IsKeyDown(Keys.Space))
            {
                string selection = mPauseMenu.GetSelectedName();

                if (selection == "Return to Game")
                {
                    mIsPaused = false;
                    SoundManager.UnPauseMusic();
                }
                else if (selection == "Load Game")
                {
                    if (this.loadFile())
                    {
                        mIsMainMenu = false;
                        //-------Could probably link what music 
                        //---is being played to the map.
                        SoundManager.PlayMusic("ThemeMusic");
                    }
                }
                else if (selection == "Save")
                {
                    this.saveFile();
                    // ADD Save FUNCTIONALITY HERE
                }
                else if (selection == "Save And Quit")
                {
                    this.saveFile();
                    SoundManager.FadeMusic();
                    Exit();
                    // ADD Save and Quit FUNCTIONALITY HERE
                }
                else if (selection == "Quit")
                {
                    SoundManager.FadeMusic();
                    Exit();
                }
            }

        }

        /// <summary>
        /// Process Input when showing the map
        /// </summary>
        protected void ProcessMapKeyboard()
        {
            if (keyState.GetPressedKeys().Length > 0)
            {
                if (!keyState.IsKeyDown(Keys.M)) mIsShowingMap = false;
            }
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            keyState = Keyboard.GetState();
            if (!mIsMainMenu && !mIsPaused && !mIsShowingMap)
            {
                if (Hero.currentHealth == 0)
                {
                    //todo: Something
                    ProcessGameOverKeyboard();
                    return;
                }
                // Created this method to handle game play input
                ProcessGameKeyboard();

                // TODO: Add your update logic here
                foreach (Update_Delegate iter in UpdateObjects)
                {
                    iter.Invoke(gameTime);
                }

                int LayerCount = Enum.GetNames(typeof(Layers)).Length;
                for (int i = 0; i < LayerCount; i++)
                {
                    Draw_Functions[i].Clear();
                }
                UpdateObjects.Clear();
                HashSet<Game_Object> TempList = MapObjects.Intersections(CurrentScreen);
                foreach (Game_Object iter in TempList)
                {
                    //---Only Start Drawing if the remove succeeded and it's a drawing object
                    if (iter is Draw_Object)
                    {
                        (iter as Draw_Object).startDraw();
                    }
                    if (iter is Logic_Object)
                    {
                        (iter as Logic_Object).startUpdate();
                    }
                }
                Hero.startDraw();
                Hero.startUpdate();
                //--------Weather Changer 10000
                List<Map_Tile> tile = TempList.OfType<Map_Tile>().ToList();
                Vector3 TempBox = CurrentScreen.Min + ((CurrentScreen.Max - CurrentScreen.Min) / 2.0f);
                Vector3 TempBoxMin = TempBox;
                TempBoxMin.Z = -1000;
                Vector3 TempBoxMax = TempBox + Vector3.One;
                TempBoxMax.Z = 1000;
                BoundingBox WeatherBox = new BoundingBox(TempBoxMin, TempBoxMax + Vector3.One);

                foreach (Map_Tile iter in tile)
                {
                    if (WeatherBox.Intersects(iter.GraphicBB))
                    {
                        Change_Weather(iter.Tile_Weather, gameTime);
                        Change_Enviornment(iter.Tile_Enviornment, gameTime);
                        break;
                    }
                }
                //-----------------------------
                effect.startUpdate();
                GameObjects = TempList.ToList<Game_Object>();
            }
            else if (mIsMainMenu)
            {
                // Created this method to handle main menu input
                ProcessMenuKeyboard();
            }
            else if (mIsPaused)
            {
                // Created this method to handle pause menu input
                ProcessPauseKeyboard();
            }
            else if (mIsShowingMap)
            {
                ProcessMapKeyboard();
            }
            lastKeyState = Keyboard.GetState();

            base.Update(gameTime);
        }

        Weather_Type currentWeather = Weather_Type.None;
        private void Change_Weather(Weather_Type weather, GameTime time)
        {
            if (weather != currentWeather)
            {
                switch (weather)
                {
                    case Weather_Type.Drizzle:
                        effect.SetRainStorm(0.5f);
                        break;
                    case Weather_Type.Heat_Wave:
                        effect.HeatWave.Amplitude = 1.5f;
                        effect.HeatWave.Phase = 192f;
                        effect.SetHeatWave();
                        break;
                    case Weather_Type.Heavy_Wind:
                        effect.HeatWave.Amplitude = 0.25f;
                        effect.HeatWave.Phase = 128;
                        effect.SetHeatWave();
                        break;
                    case Weather_Type.Light_Snow:
                        break;
                    case Weather_Type.Major_Heat_Wave:
                        effect.HeatWave.Amplitude = 1.5f;
                        effect.HeatWave.Phase = 64;
                        effect.SetHeatWave();
                        break;
                    case Weather_Type.None:
                        effect.SetGeneric();
                        effect.SetNormalLight();

                        break;
                    case Weather_Type.Rain:
                        effect.SetThunderStorm(0.05f, 160f);
                        effect.SetRainStorm(50.5f);
                        break;
                    case Weather_Type.Snow:
                        
                        break;
                    case Weather_Type.Wind:
                        effect.HeatWave.Amplitude = 0.25f;
                        effect.HeatWave.Phase = 512f;
                        effect.SetHeatWave();
                        break;
                }
                currentWeather = weather;
            }
        }
        Enviornment_Type currentEnviornment = Enviornment_Type.Normal;
        private void Change_Enviornment(Enviornment_Type enviornment, GameTime time)
        {
            if (enviornment != currentEnviornment)
            {
                switch (enviornment)
                {
                    case Enviornment_Type.Normal:
                        effect.SetNormalLight();
                        break;
                    case Enviornment_Type.BrightSun:
        				effect.SetBrightLight();
                        break;
                    case Enviornment_Type.MoonLight:
                        effect.SetMoonLight();
                        break;
                }
                currentEnviornment = enviornment;
            }
        }
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            if (!mIsMainMenu && !mIsPaused && !mIsShowingMap)
            {
                if (Hero.currentHealth == 0)
                {
                    GraphicsDevice.Clear(new Color(15, 77, 147));
                    projectionMatrix = Matrix.CreateOrthographicOffCenter(CurrentScreen.Min.X - 512, CurrentScreen.Max.X - 512, CurrentScreen.Min.Y - 384, CurrentScreen.Max.Y - 384, 0.0f, 1024.0f);
                    GraphicsDevice.RenderState.CullMode = CullMode.None;
                    int GameOverTexture = register_texture("Backgrounds\\GAME-OVER.png");
                    Rectangle GameOverRectangle = new Rectangle(GraphicsDevice.Viewport.Width / 2 - 150, GraphicsDevice.Viewport.Height / 2 - 170, 300, 340);
                    //Money Calc
                    spriteBatch.Begin();
                    spriteBatch.Draw(Texture_List[GameOverTexture], GameOverRectangle, Color.White);
                    spriteBatch.End();
                    GraphicsDevice.RenderState.DepthBufferEnable = true;
                    return;
                }
                GraphicsDevice.Clear(Color.Black);
                projectionMatrix = Matrix.CreateOrthographicOffCenter(CurrentScreen.Min.X - 512, CurrentScreen.Max.X - 512, CurrentScreen.Min.Y - 384, CurrentScreen.Max.Y - 384, 0.0f, 1024.0f);

                GraphicsDevice.RenderState.CullMode = CullMode.None;
                //effect.EnableTexture = true;
                //effect.VertexColorEnabled = true;
                LineEffect.Projection = projectionMatrix;
                LineEffect.View = viewMatrix;
                LineEffect.World = Matrix.Identity;
                Game_Effect.Projection = projectionMatrix;
                Game_Effect.View = viewMatrix;
                Game_Effect.World = Matrix.Identity;
                GraphicsDevice.VertexDeclaration = VertexColor;
                int LayerCount = Enum.GetNames(typeof(Layers)).Length;
                for (int i = 0; i < LayerCount; i++)
                {
                    Draw_Functions[i].Sort();
                    foreach (Sort_Delegate iter in Draw_Functions[i])
                    {
                        iter.draw(gameTime, GraphicsDevice);
                    }
                }
                //----------Draw Bounds
                if (bounds)
                {
                    GraphicsDevice.VertexDeclaration = VertexPosColor;

                    foreach (Game_Object iter in GameObjects)
                    {
                        SelectionColor = Color.White;
                        foreach (BoundingBox iter2 in iter.Bounding_Regions)
                        {
                            Draw_Lines(iter2);
                        }
                        SelectionColor = Color.Red;
                        foreach (BoundingBox iter2 in iter.Bounding_Weapon)
                        {
                            Draw_Lines(iter2);
                        }
                    }


                    SelectionColor = Color.White;
                    foreach (BoundingBox iter2 in Hero.Bounding_Regions)
                    {
                        Draw_Lines(iter2);
                    }
                    SelectionColor = Color.Red;
                    foreach (BoundingBox iter2 in Hero.Bounding_Weapon)
                    {
                        Draw_Lines(iter2);
                    }
                }
                GUInterface.Draw(gameTime);
            }
            else if (mIsMainMenu)
            {
                DrawMainMenu();
                mMainMenu.Update(gameTime);
                mMainMenu.Draw(spriteBatch);
            }
            else if (mIsPaused)
            {
                //GraphicsDevice.Clear(Color.Blue);
                DrawPauseMenu();
                mPauseMenu.Update(gameTime);
                mPauseMenu.Draw(spriteBatch);
            }
            else if (mIsShowingMap)
            {
                DrawMap();
            }

            base.Draw(gameTime);
        }

        private void DrawMainMenu()
        {
            Rectangle screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight);
            spriteBatch.Begin();
            spriteBatch.Draw(mMainMenuTexture, screenRectangle, Color.White);
            spriteBatch.End();
        }

        private void DrawPauseMenu()
        {
            Rectangle screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight);
            spriteBatch.Begin();
            spriteBatch.Draw(mPauseMenuTexture, screenRectangle, Color.White);
            spriteBatch.End();
        }

        private void DrawMap()
        {
            Rectangle screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight);
            spriteBatch.Begin();
            spriteBatch.Draw(mMapTexture, screenRectangle, Color.White);
            spriteBatch.End();
        }
    }
}
